package com.xa.xamall.framework.vo;

/**
 * Http请求返回的最外层对象
 */
public class R {

    /**
     * 成功状态常量
     */
    public static int SUCCESS = 0;

    /**
     * 失败状态常量
     */
    public static int ERROR   = 1;

    /**
     * 错误码,0-成功
     */
    private int code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 具体内容
     */
    private Object data;

    public R(int code) {
        this(code, null);
    }

    public R(int code, String msg) {
        this(code, msg, null, null);
    }

    public R(int code, String msg, Object data) {
        this(code, msg, data, null);
    }

    public R(int code, String msg, Object data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R ok() {
        return new R(SUCCESS, "ok");
    }

    public static R ok(String message) {
        return new R(SUCCESS, message);
    }

    public static R ok(Object data) {
        return new R(SUCCESS, "ok", data);
    }

    public static R ok(String message, Object data) {
        return new R(SUCCESS, message, data);
    }

    public static R error(String errorMsg) {
        return new R(ERROR, errorMsg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
